package com.zhuiYun.project.api.login.controller;

import com.zhuiYun.project.annotation.OptLog;
import com.zhuiYun.project.api.login.entity.User;
import com.zhuiYun.project.api.login.service.UserLoginService;
import com.zhuiYun.project.common.controller.BaseController;
import com.zhuiYun.project.common.response.CommonConstants;
import com.zhuiYun.project.common.response.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Description TODO 用户登录
 * @ClassName LoginController
 * @Author HH
 * @Date 2023/4/3 18:10
 **/
@RestController
@RequestMapping("/userLogin")
@CrossOrigin
@Slf4j
@Api(tags = "pc端登录")
public class UserLoginController extends BaseController{

    @Autowired
    UserLoginService userLoginService;

    /**
    * @Author hbx
    * @Description pc端注册检查账号名是否重复
    * @Date 2023/4/10 13:53
    * @param userName
    */
    @GetMapping("/checkLoginName")
    @ApiOperation(value = "pc端注册检查账号名是否重复")
    @OptLog(modular = "pc端注册", type = CommonConstants.SELECT, describe = "检查账号名是否重复")
    public CommonResult checkLoginName(String userName){
        return CommonResult.ok(userLoginService.checkLoginName(userName));
    }

    /**
    * @Author hbx
    * @Description 比较手机验证码是否正确
    * @Date 2023/4/17 20:16
    * @param code
    */
    @GetMapping("/comparePhoneCode")
    public CommonResult comparePhoneCode(String code){
        return CommonResult.ok(userLoginService.comparePhoneCode(code));
    }

    /**
    * @Author hbx
    * @Description pc端注册检查手机号是否重复
    * @Date 2023/4/10 14:24
    * @param phone
    */
    @GetMapping("/checkPhone")
    @ApiOperation(value = "pc端注册检查手机号是否重复")
    @OptLog(modular = "pc端注册", type = CommonConstants.SELECT, describe = "检查手机号是否重复")
    public CommonResult checkPhone(String phone){
        return CommonResult.ok(userLoginService.checkPhone(phone));
    }

    /**
    * @Author hbx
    * @Description pc端注册检查邮箱是否重复
    * @Date 2023/4/10 14:52
    * @param mail
    */
    @GetMapping("/checkMail")
    @ApiOperation(value = "pc端注册检查邮箱是否重复")
    @OptLog(modular = "pc端注册", type = CommonConstants.SELECT, describe = "检查邮箱是否重复")
    public CommonResult checkMail(String mail){
        return CommonResult.ok(userLoginService.checkMail(mail));
    }
    /**
    * @Author hbx
    * @Description pc端注册向邮箱发送验证码
    * @Date 2023/4/10 18:39
    * @param mail
    */
    @GetMapping("/registerByMailCode")
    @ApiOperation(value = "pc端注册向邮箱发送验证码")
    public CommonResult registerByMailCode(String mail){
        return CommonResult.ok(userLoginService.registerByMailCode(mail));
    }

    /**
    * @Author hbx
    * @Description pc端注册验证邮箱验证码是否正确
    * @Date 2023/4/10 19:16
    * @param code
    * @param mail
    */
    @GetMapping("/determineMailCode")
    @ApiOperation(value = "pc端注册校验邮箱验证码是否正确")
    public CommonResult determineMailCode(String mail,String code){
        return CommonResult.ok(userLoginService.determineMailCode(mail,code));
    }

    /**
    * @Author hbx
    * @Description pc端注册向邮箱发送验证码
    * @Date 2023/4/10 19:33
    * @param user
    */
    @PostMapping("/registerUsers")
    @ApiOperation(value = "pc端注册用户")
    @OptLog(modular = "pc端注册", type = CommonConstants.ADD, describe = "pc端注册用户")
    public CommonResult registerUsers(User user){
        return CommonResult.ok(userLoginService.registerUsers(user));
    }

    /**
    * @Author hbx
    * @Description pc端登录向邮箱发送验证码
    * @Date 2023/4/12 11:47
    * @param mail
    */
    @GetMapping("/loginByMailCode")
    @ApiOperation(value = "pc端登录向邮箱发送验证码")
    public CommonResult loginByMailCode(String mail){
        return CommonResult.ok(userLoginService.loginByMailCode(mail));
    }
    
    /**
    * @Author hbx
    * @Description 腾讯云发送手机短信
    * @Date 2023/4/16 19:55
    * @param phone
    */
    @GetMapping("/sendPhoneCode")
    public CommonResult sendPhoneCode(String phone){
        return userLoginService.sendPhoneCode(phone);
    }

    /**
    * @Author hbx
    * @Description 根据用户id查询用户信息
    * @Date 2023/4/19 14:07
    * @param id
    */
    @GetMapping("/getUserListByUserId")
    public CommonResult getUserListByUserId(Integer id){
        return CommonResult.ok(userLoginService.getUserListByUserId(id));
    }

}
